<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户信息列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css" rel="stylesheet">
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>用户账号：</label>
                                <input type="text" name="userAccount"/>
                            </li> <li>
                                <label>手机号：</label>
                                <input type="text" name="userPhone"/>
                            </li>
                            <li>
                                <label>姓名：</label>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <label>身份证号：</label>
                                <input type="text" name="userIdcard"/>
                            </li>
                            <li>
                                <label>邮箱：</label>
                                <input type="text" name="userEmail"/>
                            </li>
                            <!--<li class="select-time">
                                <label>出生日期：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginUserBirth]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endUserBirth]"/>
                            </li>-->
                            <li>
                                <label>固定电话：</label>
                                <input type="text" name="userTel"/>
                            </li>
                            <li>
                                <label>通讯地址：</label>
                                <input type="text" name="userAddress"/>
                            </li>
                            <li>
                                <label>邮政编码：</label>
                                <input type="text" name="userPostcode"/>
                            </li>
                            <li style="width: 450px;">
                                <label >所在地区：</label>
                                <div class="col-sm-8">
                                    <select class="selectpicker form-control" onchange="initCity()" id="userProvincecode" name="userProvincecode">
                                        <option value="">--省份--</option>
                                    </select>
                                    <select class="selectpicker form-control" id="userCitycode" name="userCitycode">
                                        <option value="">--城市--</option>
                                    </select>
                                </div>
                            </li>
                            <li>
                                <label>安全级别：</label>
                                <input type="text" name="userSecurity"/>
                            </li>
                            <li>
                                <label>是否禁用：</label>
                                <select name="isDisable">
                                    <option value="">所有</option>
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label>注册时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginCreateTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endCreateTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <!--<div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="ylyx:user:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="ylyx:user:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="ylyx:user:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="ylyx:user:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>-->
            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: layout-latest-js" />
     <th:block th:include="include :: ztree-js" />
     <script src="https://cdn.bootcdn.net/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('ylyx:user:edit')}]];
        var removeFlag = [[${@permission.hasPermi('ylyx:user:remove')}]];
        var prefix = ctx + "ylyx/user";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                searchOnEnterKey:true,
                modalName: "用户信息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'userAccount',
                    title: '用户账号'
                },{
                    field: 'userPhone',
                    title: '手机号'
                },
                {
                    field: 'userName',
                    title: '姓名'
                },{
                    field: 'userSex',
                    title: '性别'
                },
                {
                    field: 'userIdcard',
                    title: '身份证号'
                },
                {
                    field: 'userPassword',
                    title: '密码'
                },
                {
                    field: 'userEmail',
                    title: '邮箱'
                },
                {
                    field: 'userCardimage',
                    title: '身份证正面',
                    formatter: function(value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'userBackimage',
                    title: '身份证反面',
                    formatter: function(value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'userBirth',
                    title: '出生日期',
                    //获取日期列的值进行转换
                    formatter: function (value, row, index) {
                        return changeDateFormat(value)
                    }
                },
                {
                    field: 'userTel',
                    title: '固定电话'
                },
                {
                    field: 'userCityname',
                    title: '所在城市名称'
                },
                {
                    field: 'userProvincename',
                    title: '所在省份名称'
                },
                {
                    field: 'userAddress',
                    title: '通讯地址'
                },
                {
                    field: 'userPostcode',
                    title: '邮政编码'
                },
                {
                    field: 'userSecurity',
                    title: '安全级别'
                },
                {
                    field: 'isDisable',
                    title: '是否禁用'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if(row.isDisable == "是"){
                            actions.push('<a class="btn btn-warning btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="openUser(\'' + row.id + '\')"><i class="fa fa-edit"></i>启用</a>');
                        }
                        if(row.isDisable == "否"){
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="closeUser(\'' + row.id + '\')"><i class="fa fa-remove"></i>禁用</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        $(document).ready(function(){
            // 地区下拉框初始化
            $("#userProvincecode").selectpicker({width:130, liveSearch: true, liveSearchPlaceholder: "搜索" });
            $("#userCitycode").selectpicker({width:120, liveSearch: true, liveSearchPlaceholder: "搜索" });

            // 动态加载省份选项数据
            initSelectOptions("userProvincecode","0");
        });// onReady

        /**
         * 动态生成select选项
         * @param selectId
         * @returns
         */
        function initSelectOptions(selectId,parentId) {
            var selectObj = $("#" + selectId);
            $.ajax({
                url : ctx + "ylyx/user/"+parentId,
                async : false,
                type : "GET",
                success : function(result) {

                    var configs = result.rows;
                    selectObj.find("option:not(:first)").remove();
                    for (var i in configs) {
                        var addressConfig = configs[i];
                        var optionValue = addressConfig.id;
                        var optionText = addressConfig.areaName;
                        selectObj.append(new Option(optionText, optionValue));
                    }
                    debugger;
                    // 刷新select
                    selectObj.selectpicker('refresh');
                },
                error : function(result) {
                    toastr.error('获取['+ parentId + ']信息失败，原因：' + result.errorMessage);
                }
            });// ajax
        }

        /**
         * 根据选择的省份动态初始化城市options
         * @returns
         */
        function initCity() {
            // 当省份变动时，初始化城市和清空县区和街道
            var provinceSel = $("#userProvincecode").val();
            initSelectOptions("userCitycode", provinceSel);
            /*$("#requireDist").find("option:not(:first)").remove();
            $("#requireDist").selectpicker('refresh');*/
        }

        function openUser(id) {
            $.modal.confirm("确认要启用该用户？" , function() {
                $.ajax({
                    type: "post",
                    url: prefix + "/openUser?id="+id,
                    success: function(r) {
                        $.modal.msgSuccess("启用成功");
                        $.modal.reload();
                    }
                });
            });
        }

        function closeUser(id) {
            $.modal.confirm("确认要禁用该用户？" , function() {
                $.ajax({
                    type: "post",
                    url: prefix + "/closeUser?id="+id,
                    success: function(r) {
                        $.modal.msgSuccess("禁用成功");
                        $.modal.reload();
                    }
                });
            });
        }

        //创建函数
        function changeDateFormat(cellval) {
            if (cellval) {
                var date = new Date(cellval);
                var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
                var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
                var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
                return date.getFullYear() + "-" + month + "-" + currentDate;
            }
            return "";
        }
    </script>
</body>
</html>